package com.ourteam.product.requirement.api;

import org.apache.commons.lang3.StringUtils;

import com.ourteam.frame.web.AbstractSearchModel;
import com.ourteam.product.requirement.dao.ProductRequirementDAOQueryBean;
import com.ourteam.product.requirement.domain.ProductRequirementBean;

public class ProductRequirementSearchModel extends AbstractSearchModel<ProductRequirementDAOQueryBean> {

	private String requestName;

	private String requestCode;

	private String requestContent;

	private String requestType;

	private String status;

	private Long productDefineId;

	private Long creatorId;

	@Override
	public String getMappedDAOField(String aProperty) {
		return ProductRequirementBean.getMappedDAOField(aProperty);
	}

	public String getRequestName() {
		return requestName;
	}

	public void setRequestName(String requestName) {
		this.requestName = requestName;
	}

	public String getRequestCode() {
		return requestCode;
	}

	public void setRequestCode(String requestCode) {
		this.requestCode = requestCode;
	}

	public String getRequestContent() {
		return requestContent;
	}

	public void setRequestContent(String requestContent) {
		this.requestContent = requestContent;
	}

	public String getRequestType() {
		return requestType;
	}

	public void setRequestType(String requestType) {
		this.requestType = requestType;
	}

	public String getStatus() {
		return status;
	}

	public void setStatus(String status) {
		this.status = status;
	}

	public Long getProductDefineId() {
		return productDefineId;
	}

	public void setProductDefineId(Long productDefineId) {
		this.productDefineId = productDefineId;
	}

	public Long getCreatorId() {
		return creatorId;
	}

	public void setCreatorId(Long creatorId) {
		this.creatorId = creatorId;
	}

	@Override
	protected void doBuildQueryBean(ProductRequirementDAOQueryBean queryBean) throws Exception {

		ProductRequirementDAOQueryBean.Criteria criteria = queryBean.createCriteria();
		
		if(StringUtils.isNoneBlank(this.requestName)) {
			criteria.andRequestNameLike(requestName);
		}
		
		if(StringUtils.isNoneBlank(this.requestCode)) {
			criteria.andRequestCodeEqualTo(requestCode);
		}

		if(StringUtils.isNoneBlank(this.requestType)) {
			criteria.andRequestTypeEqualTo(requestType);
		}
		
		if(StringUtils.isNoneBlank(this.requestContent)) {
			criteria.andRequestContentLike(requestContent);
		}
		
		if(StringUtils.isNoneBlank(this.status)) {
			criteria.andStatusEqualTo(status);
		}
		
		if(productDefineId != null && productDefineId.longValue() > 0) {
			criteria.andProductDefineIdEqualTo(productDefineId);
		}
		
		if(creatorId != null && creatorId.longValue() > 0) {
			criteria.andCreatorIdEqualTo(creatorId);
		}
	}

}
